function add(...args1) {
  const array = [...args1]
  function fn(...args2) {
    array.push(...args2)
    return fn
  }
  fn.toString = function () {
    return array.reduce((p, c) => p + c, 0)
  }
  return fn
}

add(1)

function high(fn) {
  const length = fn.length
  const array = []
  function inFn(...args) {
    array.push(...args)
    if (array.length >= length) {
      const temp = array.splice(0, length)
      return fn(...temp)
    }
    return inFn
  }

  return inFn
}

var fn1 = high(function (a, b, c) {
  return a + b + c
})
fn1(1)(2, 3)
fn1(1)(2)(3)
fn1(1, 2, 3)
var fn2 = high(function (a, b) {
  return a + b
})
fn2(2, 3)
fn2(2)(3)
